home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
H-K
/
Inside Mac DA 2.4.cpt
/
IM Source
/
IM.Pas
next >
Wrap
Pascal/Delphi Source File
|
1987-08-09
|
14KB
|
606 lines
program Inside_Macintosh;
{ Version 2.0, 12.11.1986
Version 2.1, 26.11.1986 Bug in PageDown, PageUp beseitigt
Version 2.2, 15.12.1986 Bug Groß/Kleinschreibung beseitigt
Version 2.3, 16.01.1987 Bug Zahl/Buchstabe beseitigt
Version 2.4, 06.08.1987 Deklarationen Mac ][ und Copy/Paste hinzugefügt
Version 2.41, 09.08.1987 Backspace implementiert
Autor: Arne Schirmacher, Gutenbergstraße 14, D-6070 Langen
Der Quellcode zum Inside-Macintosh-Deskaccessory ist n i c h t
Public Domain. Alle Usergroups, Vereine ect. werden gebeten, nur
das compilierte Programm weiterzugeben.
}
uses
MacIntf;
{$U Search}
{$A+}
const
accEvent = 64;
accRun = 65;
accCursor = 66;
accMenu = 67;
accUndo = 68;
accCut = 70;
accCopy = 71;
accPaste = 72;
accClear = 73;
proc = 'PROCEDURE ';
func = 'FUNCTION ';
cons = 'CONST ';
StrListType = 'STR#';
type DAGlobals = record
i : Integer;
maxLines : Integer;
ID0,ID1,ID2,ID3,ID4 : Integer;
theDialog : DialogPtr;
StrList0 : Handle;
StrList1 : Handle;
StrList2 : Handle;
StrList3 : Handle;
StrList4 : Handle;
ScrollBar : ControlHandle;
SearchBox : Rect;
FoundBox : Rect;
CommentBox : Rect;
SearchFrame : Rect;
FoundFrame : Rect;
CommentFrame : Rect;
searchStr : Str255;
foundStr : Str255;
commentStr : Str255;
end;
DAGlobalsP = ^DAGlobals;
DAGlobalsH = ^DAGlobalsP;
procedure Search(searchStr: Ptr; list: Ptr; var i: Integer);
external;
procedure GetProc;
var
theString : Str255;
DAVarsH : DAGlobalsH;
begin
{ lokale Variablen wiederfinden }
DAVarsH := pointer(WindowPeek(FrontWindow)^.refCon);
with DAVarsH^^ do begin
{ Teilstring 'PROCEDURE', 'FUNCTION' oder 'CONST' machen }
LoadResource(StrList0);
GetIndString(theString,ID0,i);
HPurge(StrList0);
if theString[1] = 'P' then foundStr := proc;
if theString[1] = 'F' then foundStr := func;
if theString[1] = 'C' then foundStr := cons;
{ Kommentarstring machen, Index ist Byte in theString[2] }
commentStr := '';
if ord(theString[2]) >0 then begin
LoadResource(StrList4);
GetIndString(commentStr,ID4,ord(theString[2]));
HPurge(StrList4);
end; { if }
{ Prozedurnamen an foundStr anhängen }
LoadResource(StrList1);
GetIndString(theString,ID1,i);
HPurge(StrList1);
foundStr := concat(foundStr,theString);
foundStr := concat(foundStr,' ');
{ Deklaration (2 Hälften) an foundStr anhängen }
LoadResource(StrList2);
GetIndString(theString,ID2,i);
HPurge(StrList2);
foundStr := concat(foundStr,theString);
LoadResource(StrList3);
GetIndString(theString,ID3,i);
HPurge(StrList3);
foundStr := concat(foundStr,theString);
end; { with }
end;
procedure ScrollUp(theControl: ControlHandle; partCode: Integer);
var
ticks : LongInt;
DAVarsH : DAGlobalsH;
begin
{ lokale Variablen wiederfinden }
DAVarsH := pointer(WindowPeek(FrontWindow)^.refCon);
with DAVarsH^^ do begin
{ 1 Eintrag weitergehen }
Delay(5,ticks);
i := GetCtlValue(ScrollBar);
if i < maxLines then begin
i := i + 1;
SetCtlValue(ScrollBar,i);
GetProc;
TextBox(@foundStr[1],length(foundStr),FoundBox,teJustLeft);
TextBox(@commentStr[1],length(commentStr),CommentBox,teJustLeft);
end; { if }
end; { with }
end;
procedure ScrollDown(theControl: ControlHandle; partCode: Integer);
var
ticks : LongInt;
DAVarsH : DAGlobalsH;
begin
{ lokale Variablen wiederfinden }
DAVarsH := pointer(WindowPeek(FrontWindow)^.refCon);
with DAVarsH^^ do begin
{ 1 Eintrag zurückgehen }
Delay(5,ticks);
i := GetCtlValue(ScrollBar);
if i > 1 then begin
i := i - 1;
SetCtlValue(ScrollBar,i);
GetProc;
TextBox(@foundStr[1],length(foundStr),FoundBox,teJustLeft);
TextBox(@commentStr[1],length(commentStr),CommentBox,teJustLeft);
end; { if }
end; { with }
end;
procedure PageUp(theControl: ControlHandle; partCode: Integer);
var
DAVarsH : DAGlobalsH;
begin
if partCode = inPageDown then begin
{ lokale Variablen wiederfinden }
DAVarsH := pointer(WindowPeek(FrontWindow)^.refCon);
with DAVarsH^^ do begin
{ 25 Einträge weitergehen }
i := GetCtlValue(ScrollBar);
if i <> maxLines then begin
i := i + 25;
if i > maxLines then i := maxLines;
SetCtlValue(ScrollBar,i);
GetProc;
TextBox(@foundStr[1],length(foundStr),FoundBox,teJustLeft);
TextBox(@commentStr[1],length(commentStr),CommentBox,teJustLeft);
end; { if i <> }
end; { with }
end; { if partCode }
end;
procedure PageDown(theControl: ControlHandle; partCode: Integer);
var
DAVarsH : DAGlobalsH;
begin
if partCode = inPageUp then begin
{ lokale Variablen wiederfinden }
DAVarsH := pointer(WindowPeek(FrontWindow)^.refCon);
with DAVarsH^^ do begin
{ 25 Einträge zurückgehen }
i := GetCtlValue(ScrollBar);
if i <> 1 then begin
i := i - 25;
if i < 1 then i := 1;
SetCtlValue(ScrollBar,i);
GetProc;
TextBox(@foundStr[1],length(foundStr),FoundBox,teJustLeft);
TextBox(@commentStr[1],length(commentStr),CommentBox,teJustLeft);
end; { if i <> }
end; { with }
end; { if partCode }
end;
procedure HandleMouse(theEvent: EventRecord);
var
result : Integer;
itemhit : Integer;
ticks : LongInt;
myDialog : DialogPtr;
whichControl : ControlHandle;
DAVarsH : DAGlobalsH;
Pic : PicHandle;
where : Point;
theRect : Rect;
myEvent : EventRecord;
theString : Str255;
begin
{ lokale Variablen wiederfinden }
DAVarsH := pointer(WindowPeek(FrontWindow)^.refCon);
with DAVarsH^^ do begin
{ betrifft Mausklick das Desk Accessory ? }
if DialogSelect(theEvent,myDialog,itemHit) then
{ in Info-Knopf geklickt ? }
if itemHit = 5 then begin
Pic := GetPicture(ID0);
theRect.top := 10;
theRect.left := 10;
with Pic^^.picFrame do begin
theRect.bottom := bottom - top + 10;
theRect.right := 10 + right - left;
end;
EraseRect(theDialog^.portRect);
DrawPicture(Pic,theRect);
theRect := theDialog^.portRect;
SetRect(theRect,theRect.right - 90,theRect.bottom - 30,
theRect.right - 10,theRect.bottom - 10);
whichControl := NewControl(theDialog,theRect,'OK',true,0,0,0,pushButProc,0);
repeat until GetOSEvent(mDownMask,myEvent);
HiliteControl(whichControl,10);
Delay(5,ticks);
HiliteControl(whichControl,0);
Delay(5,ticks);
EraseRect(theDialog^.portRect);
InvalRect(theDialog^.portRect);
ReleaseResource(Handle(Pic));
DisposeControl(whichControl);
end; { if itemHit = 5 }
{ in Rollbalken geklickt ? }
if itemHit = 4 then begin
searchStr := '';
EraseRect(searchBox);
where := theEvent.where;
GlobalToLocal(where);
case TestControl(ScrollBar,where) of
inUpButton : result := TrackControl(ScrollBar,where,@ScrollDown);
inDownButton : result := TrackControl(ScrollBar,where,@ScrollUp);
inPageUp : result := TrackControl(ScrollBar,where,@PageDown);
inPageDown : result := TrackControl(ScrollBar,where,@PageUp);
inThumb : begin
result := TrackControl(ScrollBar,where,nil);
i := GetCtlValue(ScrollBar);
GetProc;
TextBox(@foundStr[1],length(foundStr),FoundBox,teJustLeft);
TextBox(@commentStr[1],length(commentStr),CommentBox,teJustLeft);
end;
end; { case }
end; { if itemHit = 4 }
end; { with }
end; { HandleMouse }
procedure HandleKey(theEvent: EventRecord);
var
c : char;
iOld : Integer;
j : Integer;
err : LongInt;
scrapResult : LongInt;
DAVarsH : DAGlobalsH;
theString : Str255;
begin
{ Lokale Variablen wiederfinden }
DAVarsH := pointer(WindowPeek(FrontWindow)^.refCon);
with DAVarsH^^ do begin
c := chr(BitAnd(theEvent.message,charCodeMask));
if (c in ['x','X','c','C']) and (BitAnd(theEvent.modifiers,cmdKey) <> 0) then begin
scrapResult := ZeroScrap;
scrapResult := PutScrap(length(foundStr),'TEXT',@foundStr[1]);
end { if (c in ['x','X','c','C'])... }
else begin
{ ist Zeichen Buchstabe oder Zahl ? }
if c in ['A'..'Z'] then
c := chr(ord(c) + 32);
if not ((c in ['a'..'z']) or (c in ['0'..'9'])) then
if c = chr(8) then begin
i := 0;
iOld := -1;
theString := searchStr;
searchStr := '';
LoadResource(StrList1);
HNoPurge(StrList1);
for j := 1 to length(theString) - 1 do begin
searchStr[0] := chr(j);
searchStr[j] := theString[j];
Search(@searchStr,StrList1^,i);
end; { for j := 1 }
TextBox(@searchStr[1],length(searchStr),SearchBox,teJustLeft);
end
else
i := 0
else begin
{ Zeichen in Searchbox anfügen und ausdrucken }
searchStr := concat(searchStr,c);
TextBox(@searchStr[1],length(searchStr),SearchBox,teJustLeft);
{ in Prozedurnamen suchen }
iOld := i;
LoadResource(StrList1);
HNoPurge(StrList1);
Search(@searchStr,StrList1^,i);
SetCtlValue(ScrollBar,i);
end; { else }
if i = 0 then begin
{ nichts gefunden, alle Felder löschen }
searchStr := '';
foundStr := '';
commentStr := '';
EraseRect(SearchBox);
EraseRect(FoundBox);
EraseRect(CommentBox);
end
else begin
{ wenn ein neuer Eintrag gefunden wurde, Felder aktualisieren }
if i <> iOld then begin
GetProc;
TextBox(@searchStr[1],length(searchStr),SearchBox,teJustLeft);
TextBox(@foundStr[1],length(foundStr),FoundBox,teJustLeft);
TextBox(@commentStr[1],length(commentStr),CommentBox,teJustLeft);
end; { if i <> iOld }
end; { else }
end;
end; { with }
end; { HandleKey }
procedure Open(var Device: DCtlEntry; var Block: ParamBlockRec);
var
typ : Integer;
oldPort : GrafPtr;
WPeek : WindowPeek;
m : ^Integer;
TmpPtr : Ptr;
item : Handle;
DAVarsH : DAGlobalsH;
workRect : Rect;
theString : Str255;
begin
with Device do begin
if DCtlWindow = nil then begin
{ Platz für Variablen des Desk Accessory bereitstellen }
TmpPtr := NewPtr($1000);
DCtlStorage := NewHandle(sizeof(DAGlobals));
HLock(DCtlStorage);
DisposPtr(TmpPtr);
DAVarsH := DAGlobalsH(DCtlStorage);
with DAVarsH^^ do begin
{ benötigte Resource ID Nummern berechnen }
ID0 := $BFE0 - 32 * DCtlRefNum;
ID1 := ID0 + 1;
ID2 := ID0 + 2;
ID3 := ID0 + 3;
ID4 := ID0 + 4;
{ Dialogfenster des DAs initialisieren }
theDialog := GetNewDialog(ID0,nil,pointer(-1));
DCtlWindow := pointer(theDialog);
WPeek := WindowPeek(theDialog);
WPeek^.windowKind := DCtlRefNum;
WPeek^.refCon := ord4(DAVarsH);
GetPort(oldPort);
SetPort(theDialog);
{ Rechtecke initialisieren }
GetDItem(theDialog,1,typ,item,SearchFrame);
SearchBox := SearchFrame;
InsetRect(SearchFrame,-3,-3);
GetDItem(theDialog,2,typ,item,FoundFrame);
FoundBox := FoundFrame;
InsetRect(FoundFrame,-3,-3);
GetDItem(theDialog,3,typ,item,CommentFrame);
CommentBox := CommentFrame;
InsetRect(CommentFrame,-3,-3);
{ Daten einladen }
StrList0 := GetResource(StrListType,ID0);
StrList1 := GetResource(StrListType,ID1);
StrList2 := GetResource(StrListType,ID2);
StrList3 := GetResource(StrListType,ID3);
StrList4 := GetResource(StrListType,ID4);
i := 0;
m := pointer(StrList0^);
maxLines := m^;
foundStr := 'Inside Macintosh Version 2.41';
searchStr := '';
commentStr := '';
{ Rollbalken }
GetDItem(theDialog,4,typ,item,workRect);
ScrollBar := NewControl(theDialog,workRect,'',true,
1,1,maxLines,scrollBarProc,0);
end; { with }
{ Aufräumarbeiten }
HUnlock(DCtlStorage);
SetPort(oldPort);
end; { if }
end; { with }
end; { Open }
procedure Ctl(var Device: DCtlEntry; var Block: ParamBlockRec);
var
Trick: Record
case integer of
0: (CSParam: array[0..1] of Integer);
1: (EventPtr: ^EventRecord)
end;
savedKind : Integer;
scrapResult : LongInt;
oldPort : GrafPtr;
WPeek : WindowPeek;
DAVarsH : DAGlobalsH;
begin
with Device do begin
HLock(DCtlStorage);
DAVarsH := DAGlobalsH(DCtlStorage);
with DAVarsH^^ do begin
GetPort(oldPort);
SetPort(theDialog);
WPeek := WindowPeek(theDialog);
savedKind := WPeek^.windowKind;
WPeek^.windowKind := dialogKind;
case Block.csCode of
accCut, accCopy: begin
scrapResult := ZeroScrap;
scrapResult := PutScrap(length(foundStr),'TEXT',@foundStr[1]);
end; { accCut }
accEvent: begin
Trick.CSParam[0] := Block.CSParam[0];
Trick.CSParam[1] := Block.CSParam[1];
case Trick.EventPtr^.what of
mouseDown: HandleMouse(Trick.EventPtr^);
keyDown: HandleKey(Trick.EventPtr^);
updateEvt: begin
{ alles zeichnen }
beginUpdate(theDialog);
DrawDialog(theDialog);
DrawControls(theDialog);
TextBox(@searchStr[1],length(searchStr),SearchBox,teJustLeft);
FrameRect(SearchFrame);
TextBox(@foundStr[1],length(foundStr),FoundBox,teJustLeft);
FrameRect(FoundFrame);
TextBox(@commentStr[1],length(commentStr),CommentBox,teJustLeft);
FrameRect(CommentFrame);
FrameRect(ScrollBar^^.contrlRect);
endUpdate(theDialog);
end; { updateEvt }
activateEvt: begin
if odd(Trick.EventPtr^.modifiers) then { Rollbalken aktivieren }
ShowControl(ScrollBar)
else begin {Rollbalken deaktivieren }
HideControl(ScrollBar);
FrameRect(ScrollBar^^.contrlRect);
end; { else }
end; { activateEvt }
end; { case }
end; { accEvent }
end; { case }
WPeek^.windowKind := savedKind;
HUnLock(DCtlStorage);
SetPort(oldPort);
end; { with }
end; { with }
end; { of Ctl }
procedure Close(var Device: DCtlEntry; var Block: ParamBlockRec);
var
DAVarsH : DAGlobalsH;
begin
with Device do begin
HLock(DCtlStorage);
DAVarsH := DAGlobalsH(DCtlStorage);
with DAVarsH^^ do begin
{ Application Heap aufräumen }
DisposDialog(theDialog);
ReleaseResource(StrList0);
ReleaseResource(StrList1);
ReleaseResource(StrList2);
ReleaseResource(StrList3);
ReleaseResource(StrList4);
DisposHandle(Handle(DCtlStorage));
DCtlStorage := nil;
DCtlWindow := nil;
end; { with }
end; { with }
end; { Close }
begin
end.